﻿using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using System.Data.SqlClient;
using ZhongKeSite.Entity.Configuration;

namespace ZhongKeSite.Entity
{
    public class ZhongKeContext : DbContext
    {
        public ZhongKeContext(DbContextOptions<ZhongKeContext> options) : base(options)
        {

        }
        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            string connString = ConfigurationSetting.GetConnectionString();

            SqlConnectionStringBuilder sqlConnectionStringBuilder = new SqlConnectionStringBuilder(connString);

            optionsBuilder.UseSqlServer(sqlConnectionStringBuilder.ConnectionString);

            optionsBuilder.UseLazyLoadingProxies();

            base.OnConfiguring(optionsBuilder);
        }

        public DbSet<SysUser> SysUser { get { return Set<SysUser>(); } }
        public DbSet<SysRole> SysRole { get { return Set<SysRole>(); } }
        public DbSet<SysRight> SysRight { get { return Set<SysRight>(); } }
        public DbSet<SysDictCode> SysDictCode { get { return Set<SysDictCode>(); } }
        public DbSet<SysLoginSession> SysLoginSession { get { return Set<SysLoginSession>(); } }
        public DbSet<SysRoleRight> SysRoleRight { get { return Set<SysRoleRight>(); } }
        public DbSet<SysLoginLock> SysLoginLock { get { return Set<SysLoginLock>(); } }
        public DbSet<SysLog> SysLog { get { return Set<SysLog>(); } }
        public DbSet<News> News { get { return Set<News>(); } }
        public DbSet<Category> Category { get { return Set<Category>(); } }
        public DbSet<Expert> Expert { get { return Set<Expert>(); } }
        public DbSet<FAQs> FAQs { get { return Set<FAQs>(); } }
        public DbSet<DownLoad> DownLoad { get { return Set<DownLoad>(); } }
        public DbSet<TechnologyService> TechnologyService { get { return Set<TechnologyService>(); } }
        public DbSet<MileStone> MileStone { get { return Set<MileStone>(); } }
        public DbSet<Honor> Honor { get { return Set<Honor>(); } }
        public DbSet<Partner> Partner { get { return Set<Partner>(); } }
        public DbSet<Subscribe> Subscribe { get { return Set<Subscribe>(); } }
        public DbSet<SmtpConfig> SmtpConfig { get { return Set<SmtpConfig>(); } }
        public DbSet<SmtpTemplate> SmtpTemplate { get { return Set<SmtpTemplate>(); } }
        public DbSet<Ad> Ad { get { return Set<Ad>(); } }
        public DbSet<AdSlot> AdSlot { get { return Set<AdSlot>(); } }
        public DbSet<SinglePage> SinglePage { get { return Set<SinglePage>(); } }
        public DbSet<Menu> Menu { get { return Set<Menu>(); } }
        public DbSet<Company> Company { get { return Set<Company>(); } }
        
        public DbQuery<OrdersRemain_View> OrdersRemain_View { get; set; }
        
        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {   
            modelBuilder.HasAnnotation("ProductVersion", "2.2.3-servicing-35854");

            modelBuilder.Query<OrdersRemain_View>().ToView("OrdersRemain_View");
        }
    }
}
